/* gpsiver.p - PROCEDURE TO VALIDATE SITES FOR DATA ENTRY                    */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Id:: gpsiver.p 2301 2010-11-08 07:09:06Z jvz                           $: */

/* REVISION: 7.5      LAST MODIFIED: 09/28/94   BY:  MWD  *J034*             */
/* REVISION: 9.0      LAST MODIFIED: 12/22/98   BY: *M02W* Luke Pokic        */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KS* myb               */
/* Revision: 1.8      BY: Paul Donnelly (SB)    DATE: 06/26/03   ECO: *Q00F* */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.9      BY: Alex Joy              DATE: 01/14/08   ECO: *P6JL* */
/* Revision:   $      BY: Rijoy Ravindran       DATE: 10/15/08   ECO: *Q1S4* */
/*-Revision end--------------------------------------------------------------*/
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*                                                                           */
/*****************************************************************************/
/* This subroutine determines whether a particular user is allowed to        */
/* enter data for a given site, based on his assigned user groups            */
/* It looks up the si_mstr based on either the si_recid (if available) or    */
/* the site.  If the si_mstr is found and has security assigned, compares    */
/* to see if any of the user's groups is among the security groups           */
/* (si_canrun) for the site.  Returns a code of 1 for authorized, 0 for NOT  */
/* authorized.  The calling program is expected to display any messages      */
/* and/or take other action based on that return code.                       */
/*                                                                           */
/* Called by icedit1.i and icedit2.i transaction edit routines as well as a  */
/* number of maintenance routines which get user data entry by site.         */
/*****************************************************************************/
/*  parameters used:                                                         */
/* input variables:        sisite                  input site                */
/*                         si_recno                recid of site being       */
/*                                                 processed                 */
/* output variable:        authorized              integer return code       */
/*                                                 1=authorized; 0-not auth  */
/*****************************************************************************/


{us/bbi/mfdeclre.i}           /* COMMON VARIABLES                  */
{us/bbi/mf1.i}            /* ADDITIONAL COMMON VARIABLES, SUCH */
/* AS GLOBAL_USER_GROUPS             */

define input  parameter sisite      like si_site.
define input  parameter si_recno    as   recid.
define output parameter authorized  as   integer initial 1.

define variable group_indx          as   integer.

/* CHECK SITE FOR USER GROUP AUTHORIZATION */
if si_recno <> ?
then
   for first si_mstr
      where recid(si_mstr) = si_recno
      no-lock:
   end. /* FOR FIRST SI_MSTR */
else
   for first si_mstr
      where si_mstr.si_domain = global_domain
      and  si_site = sisite
      no-lock:
   end. /* FOR FIRST SI_MSTR */

if     available si_mstr
   and si_canrun <> ""
then do:
   authorized = 0.

   if    can-do (si_canrun + ",!*",global_userid)
      or can-do (si_canrun + ",!*",global_user_groups)
   then
      authorized = 1.

   if authorized = 0
   then
   do group_indx = 1 to num-entries(global_user_groups)
   while authorized = 0:
      if can-do (si_canrun + ",!*",
         entry(group_indx, global_user_groups))
         or can-do (si_canrun + ",!*",global_userid)
         then
            authorized = 1.
   end.  /* DO WHILE */
end.  /* (IF AVAILABLE SI_MSTR AND...) */
